/**
 * @Description:
 * @Author 卞鹏飞 <228443632@qq.com>
 * @create 05/05/25 PM6:11
 */
import { CanActivate, ExecutionContext, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
import { Observable } from 'rxjs';
import { Request } from 'express';
import { Reflector } from '@nestjs/core';

@Injectable()
export class PermissionGuard implements CanActivate {
  @Inject()
  private readonly reflector: Reflector;

  // constructor(private readonly reflector: Reflector) {}
  canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
    const req = context.switchToHttp().getRequest<Request>();

    const prem = this.reflector.getAllAndOverride<string>('permission', [context.getHandler(), context.getClass()]);

    // if (true) {
    //   throw new HttpException(
    //     {
    //       code: '200001',
    //       message: '权限不足',
    //     },
    //     HttpStatus.OK,
    //   );
    // }

    return true;
  }
}
